/**
 * 功能:TK_OUT_WAREHOUSE Service类
 * 开发人员:yaren
 * 创建时间:2012/4/22 12:15:56
 */
package com.towker.frame.service.warehouse;

import org.springframework.stereotype.Service;
import com.towker.core.db.EntityDao;
import com.towker.core.db.BaseService;
import com.towker.frame.model.warehouse.OutWarehouse;
import com.towker.frame.dao.warehouse.OutWarehouseDao;

@Service
public class OutWarehouseService extends BaseService<OutWarehouse, java.lang.Long>
{
	private OutWarehouseDao dao;
	
	public void setOutWarehouseDao(OutWarehouseDao dao)
	{
		this.dao = dao;
	}

	@SuppressWarnings("unchecked")
	@Override
	protected EntityDao getEntityDao()
	{
		return this.dao;
	}
	
	/**
	 * 生成7位的出仓单号
	 * @return
	 */
	public String getNewOutCode(){
		String sendSn = "CC";
		String lastSendSn = dao.getLastOutCode();
		String num = "";
		if (lastSendSn==null || "".equals(lastSendSn)) {
			sendSn = sendSn+"0000001";
		}else{
			int parm = Integer.parseInt(lastSendSn.substring(2,9));
			if (parm>=1 && parm<9) {
				num = "000000"+(parm+1);
			}else if(parm>=9 && parm<99){
				num = "00000"+(parm+1);
			}else if(parm>=99 && parm<999){
				num = "0000"+(parm+1);
			}else if(parm>=999 && parm<9999){
				num = "000"+(parm+1);
			}else if (parm>=9999 && parm<99999) {
				num = "00"+(parm+1);
			}else if (parm>=99999 && parm<999999) {
				num = "0"+(parm+1);
			}else if (parm>=999999 && parm<9999999) {
				num = String.valueOf(parm+1);
			}
		}
		sendSn = sendSn+num;
		return sendSn;
	}
}
